// Remember you will need to change this to be "TXF.h" if your header file is in the project directory
#include <TXF.h>
#include <iostream>


using namespace std;
using namespace TXF;
using namespace TXFSTL;


int main( int argc, char* argv[] )
{
	// Create an empty xml document
	Document doc;

	// Read data from an xml file into our xml document
	if ( doc.Read( "TXFSample1.xml" ) == false )
	{
		cerr << "Failed to read xml file" << endl;
		return -1;
	}

	// Obtain the root element (menu in the xml file)
	Element root = doc.RootElement();
	cout << "The root element is a " << root.Name() << " element" << endl;

	// Read the meal attribute from the root element
	cout << "The meal is " << root.Attribute( "meal" ) << endl;

	// Determine how many children an element has
	int nChildren = root.ChildCount();
	cout << "The root element has " << nChildren << " child elements" << endl;

	// Obtain all the Fruit children
	list<Element> fruits = root.Children( "fruit" );

	// Output info on all the of fruits
	for ( list<Element>::iterator iter = fruits.begin(); iter != fruits.end(); iter++ )
	{
		Element fruit = *iter;

		// Read the name attribute
		cout << "This fruit is called " << fruit.Attribute( "name" );

		// Determine if the element has a ripe element child
		if ( fruit.HasChild( "ripe" ) == true )
		{
			cout << " and it is ";

			// Get the first ripe child element
			Element ripe = fruit.FirstChild( "ripe" );

			// Read the contents of the element
			if ( ripe.Content() == "false" )
				cout << "not ";
			cout << "ripe.";
		}
		else
			cout << " and I do not know if it is ripe.";

		// Determine the prices
		float x, y;
		fruit.FirstChild( "prices" ).Content() >> x >> y;
		cout << " The prices are " << x << " and " << y << endl;
	}

	list<Element> billys;

	// Find any fruits called billy
	billys = root.Query( "child::fruit[ attribute::name = 'billy' ]" );
	if ( billys.size() > 0 )
		cout << "There is at least one fruit called billy" << endl;

	// Find any vegatables called billy
	billys = root.Query( "child::vegatable[ attribute::name = 'billy' ]" );
	if ( billys.size() > 0 )
		cout << "There is at least one vegatable called billy" << endl;

	// Find any elements called billy
	billys = root.Query( "child::*[ attribute::name = 'billy' ]" );
	if ( billys.size() > 0 )
		cout << "There is at least one element called billy" << endl;

	return 0;
}
